package ambientes;

import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.BevelBorder;

public class DiagramaSequenciaDrawLine extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	ArrayList<JComboBox<String>> comboBox = new ArrayList<JComboBox<String>>();
	ArrayList<JTextPane> textPane = new ArrayList<JTextPane>();
	ArrayList<JTextPane> txtpnBanda = new ArrayList<JTextPane>();

	String bandas[] = { "Banda A", "Banda B", "Banda C", "Banda D" };

	public DiagramaSequenciaDrawLine() {
		setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		setLayout(null);
		setOpaque(false);
		
		int y = 44;
		for (int i = 0; i < bandas.length; i++, y+=96) {
			txtpnBanda.add(new JTextPane());
			txtpnBanda.get(i).setText(bandas[i]);
			txtpnBanda.get(i).setBounds(22, y, 68, 24);
			txtpnBanda.get(i).setOpaque(false);
			txtpnBanda.get(i).setEditable(false);
			add(txtpnBanda.get(i));
		}

		y = 12;
		int i = 0;
		for (; i < 12; i++, y += 32) {

			comboBox.add(new JComboBox<String>());
			comboBox.get(i).setName("combo_" + i);
			comboBox.get(i).setBounds(208, y, 100, 24);
			add(comboBox.get(i));

			if (i < 3) {
				comboBox.get(i).addItem("Selecione");
				comboBox.get(i).addItem("Banda B");
				comboBox.get(i).addItem("Banda C");
				comboBox.get(i).addItem("Banda D");
			} else if (i < 6) {
				comboBox.get(i).addItem("Selecione");
				comboBox.get(i).addItem("Banda A");
				comboBox.get(i).addItem("Banda C");
				comboBox.get(i).addItem("Banda D");

			} else if (i < 9) {
				comboBox.get(i).addItem("Selecione");
				comboBox.get(i).addItem("Banda A");
				comboBox.get(i).addItem("Banda B");
				comboBox.get(i).addItem("Banda D");

			} else {
				comboBox.get(i).addItem("Selecione");
				comboBox.get(i).addItem("Banda A");
				comboBox.get(i).addItem("Banda B");
				comboBox.get(i).addItem("Banda C");
			}
			textPane.add(new JTextPane());
			textPane.get(i).setBounds(378, y, 195, 24);
			textPane.get(i).setEditable(false);
			add(textPane.get(i));
		}

	}

	public void paintComponent(Graphics g) {
		paintComponents(g);

		int i = 0;
		for (; i < 12; i++) {
			int banda;
			if(i < 3){
				banda = 0;
			} else if(i < 6){
				banda = 1;
			} else if(i < 9){
				banda = 2;
			}else{
				banda = 3;
			}
			
			g.drawLine(txtpnBanda.get(banda).getX() + txtpnBanda.get(banda).getWidth(),
					txtpnBanda.get(banda).getY() + txtpnBanda.get(banda).getHeight() / 2, comboBox
							.get(i).getX(), comboBox.get(i).getY()
							+ comboBox.get(i).getHeight() / 2);
			g.drawLine(comboBox.get(i).getX() + comboBox.get(i).getWidth(),
					comboBox.get(i).getY() + comboBox.get(i).getHeight() / 2,
					textPane.get(i).getX(), textPane.get(i).getY()
							+ textPane.get(i).getHeight() / 2);
		}
	}

}
